package company.baidu;

import java.util.Scanner;

public class BD2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int cows = sc.nextInt();
            int nums = sc.nextInt();
            int[] array = new int[cows + 1];
            for (int j = 0; j < nums; j++) {
                int nextInt = sc.nextInt();
                for (int k = 0; k < nextInt; k++) {
                    int start = sc.nextInt();
                    int end = sc.nextInt();
                    for (int l = start; l <= end; l++) {
                        array[l]++;
                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            int count = 0;
            int length = array.length;
            for (int j = 0; j < length; j++) {
                if (array[j] == nums) {
                    count++;
                    sb.append(j).append(" ");
                }
            }
            System.out.println(count);
            System.out.println(sb);
        }
    }
}
